﻿Public Class 修改密码

    '关闭窗体
    Private Sub 修改密码_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        PWchangeFM = Nothing
    End Sub

    '快捷键
    Private Sub 修改密码_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Enter Then
            Button1_Click(sender, e)
        End If
    End Sub

    '窗体加载
    Private Sub 修改密码_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label2.Text = AccountName
    End Sub

    '确定修改密码
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim old_pw As String = Trim(TextBox1.Text)
        Dim new_pw As String = Trim(TextBox2.Text)
        Dim ne2_pw As String = Trim(TextBox3.Text)

        If old_pw = "" Then MsgBox("请输入原密码！") : TextBox1.Focus() : Exit Sub
        If new_pw = "" Then MsgBox("请输入新密码！") : TextBox2.Focus() : Exit Sub
        If ne2_pw = "" Then MsgBox("请再输入输入一次新密码！") : TextBox3.Focus() : Exit Sub

        If new_pw <> ne2_pw Then MsgBox("两次输入的新密码不一致，请重新输入！") : TextBox2.Focus() : Exit Sub

        Dim sqlstr As String = "select * from 用户表 where 用户名 ='" + AccountName + "'"
        Dim dst As DataTable = SQLtoDataSet(sqlstr).Tables(0)
        If dst.Rows.Count > 0 Then
            Dim PW As String = dst.Rows(0).Item("密码").ToString
            If old_pw <> PW Then MsgBox("原密码不正确，请重新输入！") : TextBox1.Focus() : Exit Sub

            sqlstr = "update 用户表 set 密码 = '" + new_pw + "' where 用户名 ='" + AccountName + "'"
            SQLupdata(sqlstr)
            MsgBox("修改密码成功！")
            Me.Close()

        Else
            MsgBox("没有找有用户'" + AccountName + "'!")
        End If

    End Sub

End Class